<script type="text/javascript">
	$(function(){
		$("#frmMain").validate({
			rules: 
			{
				name: 
				{ 
					required: true,
					remote: 'account/check_account/' + $('select[name=fund_id] option:selected').val()
				},
				code:
				{
					required: true
				}
			},
			
			messages:
			{
				name: 
				{ 
					required: "กรุณากรอกชื่อบัญชีค่ะ",
					remote: 'มีชื่อบัญชีนี้ในระบบแล้วค่ะ'
				},
				code:
				{
					required: "กรุณากรอกรหัสบัญชีค่ะ"
				}
			}
		});
		
		$('select[name=category_id]').change(function(){
			if(($(this).val()==1)||($(this).val()==2)){
				$('.type').remove();
				$(this).parent().parent().after('<tr class="type"><th>ประเภทบัญชี</th><td>' + $('#type'+ $(this).val()).html() + '</td></tr>');
			}
			else
			{
				$('.type').remove();
			}
		})
		
		$('select[name=group_id]').change(function(){
			if($(this).val()==1){
				$('.group').remove();
				$(this).parent().parent().after('<tr class="group">\
											<th>ประเภทเงิน</th>\
											<td>\
												<input type="radio" name="money" value="1"  /> เงินสด\
												<input type="radio" name="money" value="2"  /> เงินฝากธนาคาร\
											</td>\
											</tr>');
			}
			else
			{
				$('.group').remove();
			}
		})
		
		<?php if(!$rs['category_id']): ?>
		if(($('select[name=category_id] option:selected').val()==1)||($('select[name=category_id] option:selected').val()==2)){
			$('.type').remove();
			$('select[name=category_id]').parent().parent().after('<tr class="type"><th>ประเภทบัญชี</th><td>' + $('#type'+ $('select[name=category_id] option:selected').val()).html() + '</td></tr>');
		}
		else
		{
			$('.type').remove();
		}
		<?php endif ?>
	})
	
	
</script>
<h1><?php echo $fund['name'] ?></h1>
<ul id="breadcrumb">
	<li><span>จัดการข้อมูลหลัก</span></li>
	<li>ชื่อบัญชี</li>		
</ul>
<div id="content">
<form id="frmMain" action="account/save" method="post" >
<table class="form">
	<tr><th>หมวดบัญชี</th><td><?php echo form_dropdown('category_id',get_option('ID','NAME','ACCOUNT_CATEGORIES'),$rs['category_id']) ?></td></tr>
	<?php if(($rs['category_id']==1)OR($rs['category_id']==2)): ?>
	<tr class="type"><th>ประเภทบัญชี</th><td><?php echo form_dropdown('type_id',get_option('ID','NAME','ACCOUNT_TYPES',' CATEGORY_ID = '.$rs['category_id']),$rs['type_id']) ?></td></tr>
	<?php endif ?>
	<tr><th>กลุ่มบัญชี</th><td><?php echo form_dropdown('group_id',get_option('ID','NAME','ACCOUNT_GROUPS'),$rs['group_id'],'','ไม่มี') ?></td></tr>
	<?php if($rs['group_id']==1): ?>
	<tr class="group">
		<th>ประเภทเงิน</th>
		<td>
			<input type="radio" name="money" value="1" <?php echo ($rs['money']==1)?'checked="checked"':'' ?> /> เงินสด
			<input type="radio" name="money" value="2" <?php echo ($rs['money']==2)?'checked="checked"':'' ?> /> เงินฝากธนาคาร
		</td>
	</tr>
	<?php endif ?>
	<tr><th>ชื่อบัญชี</th><td><input type="text" name="name" value="<?php echo $rs['name'] ?>" /></td></tr>
	<tr><th>รหัสบัญชี</th><td><input type="text" name="code" value="<?php echo $rs['code'] ?>" /></td></tr>
	<tr>
		<th></th>
		<td>
			<input type="submit" value="<?php echo lang('btn_submit')?>" />
			<input type="button" value="<?php echo lang('btn_back')?>"  onclick="window.location = 'division/group'" />
			<input type="hidden" name="ID" value="<?php echo $rs['id'] ?>" />
			<?php echo form_hidden('fund_id',$fund['id']) ?>
		</td>
	</tr>
</table>
</form>
</div>

<div id="type1" style="display:none;">
	<?php echo form_dropdown('type_id',get_option('ID','NAME','ACCOUNT_TYPES',' CATEGORY_ID = 1')) ?>
</div>
<div id="type2" style="display:none;">
	<?php echo form_dropdown('type_id',get_option('ID','NAME','ACCOUNT_TYPES',' CATEGORY_ID = 2')) ?>
</div>
